package com.geek.javase.ch01.bams;

/*
 *@author wangpeng
 *2025/10/9 20:44
 *@description TODO
 */
//银行账户类完全封装
public class Account {
    // 私有属性 - 完全封装
    private Long id;              // 账户号码
    private String password;      // 账户密码
    private String name;          // 真实姓名
    private String personId;      // 身份证号码
    private String email;         // 电子邮箱
    private double balance;       // 账户余额

    // 无参构造方法
    public Account() {
        this.id = 0L;
        this.password = "";
        this.name = "";
        this.personId = "";
        this.email = "";
        this.balance = 0.0;
    }

    // 有参构造方法 - 用于设置必要的属性
    public Account(Long id, String password, String name, String personId, String email, double balance) {
        this.id = id;
        this.password = password;
        this.name = name;
        this.personId = personId;
        this.email = email;
        this.balance = balance;
    }

    // Getter 和 Setter 方法
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPersonId() {
        return personId;
    }

    public void setPersonId(String personId) {
        this.personId = personId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    // 存款方法
    public Account deposit(double amount) {
        if (amount > 0) {
            this.balance += amount;
            System.out.println("存款成功！存入金额：" + amount + "，当前余额：" + this.balance);
        } else {
            System.out.println("存款失败！存款金额必须大于0");
        }
        return this;
    }

    // 取款方法
    public Account withdraw(double amount) {
        if (amount <= 0) {
            System.out.println("取款失败！取款金额必须大于0");
        } else if (amount > this.balance) {
            System.out.println("取款失败！余额不足。当前余额：" + this.balance + "，尝试取款：" + amount);
        } else {
            this.balance -= amount;
            System.out.println("取款成功！取出金额：" + amount + "，当前余额：" + this.balance);
        }
        return this;
    }
}